function fsz = filesize(filename)
% filesize  - return a file's size in bytes
%
% FORMAT:       fsz = filesize(filename)
%
% Input fields:
%
%       filename    filename
%
% Output fields:
%
%       fsz         filesize
%
% Note: returns NaN if the file doesn't exist

% Version:  v0.7f
% Build:    8110521
% Date:     Nov-05 2008, 9:00 PM CET
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin < 1 || ...
   ~ischar(filename) || ...
    isempty(filename) || ...
    exist(filename(:)', 'file') ~= 2
    fsz = NaN;
else
    fsz = dir(filename(:)');
    fsz = fsz.bytes;
end
